'''
https://leetcode.cn/problems/clone-n-ary-tree
'''
from typing import Optional, List


# Definition for a Node.
class Node:
    def __init__(self, val: Optional[int] = None, children: Optional[List['Node']] = None):
        self.val = val
        self.children = children if children is not None else []

class Solution:
    def cloneTree(self, root: 'Node') -> 'Node':
        def f(root):
            if not root:
                return None
            res = Node(root.val)
            for child in root.children:
                res.children.append(f(child))
            return res
        return f(root)